//node 后端服务器

const projectApi = require('./api/projectApi');
const userApi = require('./api/userApi');
// const qiniuApi = require('./api/qiniuApi');
const bodyParser = require('body-parser');
const express = require('express');//引入express
var cookieParser = require('cookie-parser');
const app = express();

// app.use(bodyParser.json({limit : '2100000kb'}));
app.use(bodyParser.urlencoded({
    extended: false
}));

// app.use(express.bodyParser({limit : "2100000kb"}));
app.use(express.json({ limit: '2100000kb' }));

app.use(cookieParser());
//后端api路由
app.use('/api/projectApi', projectApi);
app.use('/api/userApi', userApi);
// app.use('/api/qiniuApi', qiniuApi)

//设置请求头
app.all('/*', async function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', '*');
    //Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行
    //     res.header('Access-Control-Allow-Headers', 'content-type,自定义内容,自定义内容,自定义内容');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("X-Powered-By", ' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    res.cookie('SCN', 'app', { maxAge: 1000 * 3600 * 24 * 7, secure: false, path: '/' });

    next();
});

//监听端口
app.listen(3000);

//打印 成功监听端口3000
console.log('success listen at port :3000......');
